var isAndroid = false;
const canvasId = 'canvas1';
var isDeviceMotion = false;

Page({
  data: {
    isAuth: false,
    src: '',
    width:wx.getSystemInfoSync().windowWidth,
    height:wx.getSystemInfoSync().windowHeight,
  },
  onLoad() {
    const _this = this
    this.modelloaded()
    //获取设备信息
    const res = wx.getSystemInfoSync();
    console.log(res.system);
    if (res.system.indexOf('Android') !== -1) {
      isAndroid = true;
    }

  },
  onShow(){

  },
  onUnload(){
  },
// 模型架加载完之后，隐藏提示文字
modelloaded(){
  var that=this;

  wx.startDeviceMotionListening({
    interval: 'normal',
    success:function(res){
    },
    fail:function(){

    }
  })

  wx.onDeviceMotionChange((res) => {
    var fx=res.alpha.toFixed(2)
    var jd=res.beta.toFixed(2)
    console.log()
  })
},
  // 打开授权设置界面
  openSetting() {
    const _this = this
    let promise = new Promise((resolve, reject) => {
      wx.showModal({
        title: '授权',
        content: '请先授权获取摄像头权限',
        success(res) {
          if (res.confirm) {
            wx.openSetting({
              success(res) {
                if (res.authSetting['scope.camera']) { // 用户打开了授权开关
                  resolve(true)
                } else { // 用户没有打开授权开关， 继续打开设置页面
                  _this.openSetting().then(res => {
                    resolve(true)
                  })
                }
              },
              fail(res) {
                console.log(res)
              }
            })
          } else if (res.cancel) {
            _this.openSetting().then(res => {
              resolve(true)
            })
          }
        }
      })
    })
    return promise;
  },

  takePhoto() {
    const ctx = wx.createCameraContext()
    ctx.takePhoto({
      quality: 'high',
      success: (res) => {
        this.setData({
          src: res.tempImagePath
        })
        wx.previewImage({
          current: res.tempImagePath, // 当前显示图片的http链接
          urls: [res.tempImagePath] // 需要预览的图片http链接列表
        })
      }
    })
  }
})